package com.CST.controller.ys;

import com.CST.common.api.ResultObject;
import com.CST.dto.ys.YsDictionaryDTO;
import com.CST.entity.ys.YsDictionary;
import com.CST.service.ys.YsDictionaryService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qtx
 * @since 2023-05-07
 */
@Api(tags = "字典管理")
@RestController
@RequestMapping("/ysDictionary")
public class YsDictionaryController {

    private final YsDictionaryService service;

    public YsDictionaryController(YsDictionaryService service) {
        this.service = service;
    }

    @ApiOperation("分页查询")
    @PostMapping("/listYsDictionaryPage")
    public ResultObject<IPage<YsDictionary>> listYsDictionaryPage(@RequestBody YsDictionaryDTO dto){
        return ResultObject.success(service.listYsDictionaryPage(dto))                                 ;
    }

    @ApiOperation("下拉框查询")
    @GetMapping("/listYsDictionary")
    public ResultObject<List<YsDictionary>> listYsDictionary(@RequestParam String selectType, String name){
        return ResultObject.success(service.listYsDictionary(selectType,name));
    }

    @ApiOperation("新建或编辑")
    @PostMapping("/saveOrUpdateYsDictionary")
    public ResultObject<Boolean> saveOrUpdateYsDictionary(@RequestBody YsDictionary entity){
        return ResultObject.success(service.saveOrUpdateYsDictionary(entity));
    }

    @ApiOperation("更新状态")
    @GetMapping("/updateYsDictionaryStatus")
    public ResultObject<Boolean> updateYsDictionaryStatus(@RequestParam Integer id){
        return ResultObject.success(service.updateStatus(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/removeYsDictionaryById")
    public ResultObject<Boolean> removeYsDictionaryById(@RequestParam Integer id){
        return ResultObject.success(service.removeYsDictionaryById(id));
    }
}
